package com.zdcp.config;

import javax.sql.DataSource;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;

import com.zaxxer.hikari.HikariDataSource;

/**
 * 数据源配置
 * @author yweijian
 * @date 2019年8月30日
 * @version 1.0
 */
@Configuration
public class DataSourceConfig {
	
	@Bean(value="system")
	public DataSource systemDatasource(Environment env) {
		HikariDataSource hikariDataSource = new HikariDataSource();
		hikariDataSource.setJdbcUrl(env.getProperty("spring.datasource.system.url"));
		hikariDataSource.setUsername(env.getProperty("spring.datasource.system.username"));
		hikariDataSource.setPassword(env.getProperty("spring.datasource.system.password"));
		hikariDataSource.setDriverClassName(env.getProperty("spring.datasource.system.driver-class-name"));
		return hikariDataSource;
	}
	
	@Bean(value="generator")
	public DataSource generatorDatasource(Environment env) {
		HikariDataSource hikariDataSource = new HikariDataSource();
		hikariDataSource.setJdbcUrl(env.getProperty("spring.datasource.generator.url"));
		hikariDataSource.setUsername(env.getProperty("spring.datasource.generator.username"));
		hikariDataSource.setPassword(env.getProperty("spring.datasource.generator.password"));
		hikariDataSource.setDriverClassName(env.getProperty("spring.datasource.generator.driver-class-name"));
		return hikariDataSource;
	}
	
	@Bean(value="demo")
	public DataSource demoDatasource(Environment env) {
		HikariDataSource hikariDataSource = new HikariDataSource();
		hikariDataSource.setJdbcUrl(env.getProperty("spring.datasource.demo.url"));
		hikariDataSource.setUsername(env.getProperty("spring.datasource.demo.username"));
		hikariDataSource.setPassword(env.getProperty("spring.datasource.demo.password"));
		hikariDataSource.setDriverClassName(env.getProperty("spring.datasource.demo.driver-class-name"));
		return hikariDataSource;
	}

}



